<?php

class Env {

    public static function isDeveloper() {
       return Env::isWindows();
    }

    public static function isMailFunctionsEnabled() {
        return !self::isWindows();
        //return (bool) ini_get('sendmail_path');
    }

    public static function isConsoleCall() {
        return (isset($_SERVER['SESSIONNAME']) && $_SERVER['SESSIONNAME'] == 'Console');
    }

    private static $tmpDir = null;

    public static function getTmpDir() {

        if (self::$tmpDir === null) {

            try {
                $webTmpDir = Dir::getRoot() . Settings::config('system')->get('pathes', 'temp');
                if (file_exists($webTmpDir))
                    return self::$tmpDir = Dir::addEndslash($webTmpDir);
            } catch (NoConfigException $e) {}

            $unixTempPath = '/tmp/';
            if (file_exists($unixTempPath))
                return self::$tmpDir = $unixTempPath;

            if (!empty($_SERVER['TEMP']))
                return self::$tmpDir = Dir::addEndslash($_SERVER['TEMP']);

            throw new Exception('cannot determine temp directory');
        }

        return self::$tmpDir;
    }

    public static function isWindows() {
        return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
    }

    private static function getPathSplitter() {
        return self::isWindows() ? ';' : ':';
    }

    public static function addIncludePath($dirname) {

        $arrPathes = explode(self::getPathSplitter(), ini_get('include_path'));

        if (!in_array($dirname, $arrPathes)) {
            $arrPathes[] = $dirname;
            ini_set('include_path', implode(self::getPathSplitter(), $arrPathes));
        }
    }
}

?>